#!/opt/lampp/bin/perl 

use DBI;
use CGI;

my $user_name = "traker";
my $user_password = "mckenna";
my $sql_server = "localhost";
my $db_name = "ttraker";
my $back_loc = "/home/alan/Dropbox";

my $dbh;
initialize_dbi();

backup_dbase();

sub initialize_dbi
{
   $drh = DBI->install_driver( 'mysql' );
   $dbh = DBI->connect("DBI:mysql:$db_name:$sql_server", $user_name, $user_password);
   die "Cannot connect: $D: $DBI::errstr\n"
      unless $dbh;
}

sub run_statement
{
   my $stmt = "$_[0]";
   $sth = $dbh ->prepare($stmt);
   $sth->execute;
}


sub backup_dbase 
{
	my $stmnt = "SELECT DATE_FORMAT(CURDATE(), '%Y_%b_%d_TT.sql')";
	run_statement ($stmnt);
	$rs = $sth->fetchall_arrayref();
	my $name = $rs->[0]->[0];
	$sth->finish;
#	print "mysqldump -p$user_password -u $user_name $db_name > ${back_loc}/${name}\n";	
	system ("mysqldump -p$user_password -u $user_name $db_name > ${back_loc}/${name}");
	return $name;
}



